'''
Created on 2011-3-4

@author: bnw
'''
import urllib2
from BeautifulSoup import BeautifulSoup, Tag
import re
from stocktable import stocklist

if __name__ == '__main__':
    
    for stock in stocklist:
        stockid = stock[0]
##        if stockid != '000401':
##            continue
        print stockid
        urlstr = "http://quotes.money.163.com/f10/gsjj_" + stockid + ".html"
        page = urllib2.urlopen(urlstr)
        soup = BeautifulSoup(page)
        fpathstr = "F:/data/corpinfo.txt"
        f = open(fpathstr, 'w')
        trs = soup('table', id = 'tbl_profile')[0].tbody('tr')
        data1 = trs[0]('td')[1].string
        data2 = trs[1]('td')[1].string
        data3 = trs[4]('td')[1].string
        data4 = trs[5]('td')[1].string
        data5 = trs[6]('td')[1].string
        data6 = trs[7]('td')[1].string
        f.write(data1)
        f.write('\t')
        f.write(data2)
        f.write('\t')
        f.write(data3)
        f.write('\t')
        f.write(data4)
        f.write('\t')
        f.write(data5)
        f.write('\t')
        f.write(data6)
        f.write('\n')
        f.closed     
        
    
